package com.asset.salesforce.domain;


import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Index;

import javax.persistence.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Entity
@Table(name="users")
//@Cache(usage= CacheConcurrencyStrategy.READ_WRITE)
public class User implements Serializable {

    private Integer id;
    private String username;
    private String email;
    private String password;
    private List<Role> roles = new ArrayList<Role>();
    private Employee companyId;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="users_id_seq")
	@SequenceGenerator(name="users_id_seq",sequenceName="users_id_seq",allocationSize=1)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * Returns the username associated with this user account;
     *
     * @return the username associated with this user account;
     */
    @Basic(optional=false)
    @Column(length=100)
    @Index(name="idx_users_username")
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic(optional=false)
    @Index(name="idx_users_email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Returns the password for this user.
     *
     * @return this user's password
     */
    @Basic(optional=false)
    @Column(length=255)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


    @ManyToMany
    @JoinTable(name="users_roles")
//    @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

	/**
	 * @return the companyId
	 */
    @OneToOne
	@JoinColumn(name = "company_id")
	public Employee getCompanyId() {
		return companyId;
	}

	/**
	 * @param companyId the companyId to set
	 */
	public void setCompanyId(Employee companyId) {
		this.companyId = companyId;
	}

}


